package com.zc.exception;

import com.zc.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author zc
 * @Date 2025/8/16
 * @apiNote 全局异常捕获器
 */
@ControllerAdvice("com.zc.controller")
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody //将result对象转换成json的格式
    public Result error(Exception e) {
        return Result.error("系统异常");
    }

    @ExceptionHandler(CustomerException.class)
    @ResponseBody //将result对象转换成json的格式
    public Result customerError(CustomerException e) {
        return Result.error(e.getCode(),e.getMsg());
    }
}

